package br3akr.DeadlyDinnerParty.Server.World;

import java.util.HashSet;
import java.util.Set;

public class Key extends Item {
	Set<Exit> exitLocks;
	Set<Handcuffs> handcuffLocks;
	Set<Chest> chestLocks;
	boolean masterKey;
	
	public Key(String name, String description, 
			Set<String> actions, Set<Exit> doorLocks, 
			Set<Handcuffs> handcuffLocks, boolean masterKey) {
		super(name, description, actions);
		
		this.masterKey = masterKey;
		
		if (doorLocks != null) {
			this.exitLocks = doorLocks;
		} else {
			this.exitLocks = new HashSet<Exit>();
		}
		
		if (handcuffLocks != null) {
			this.handcuffLocks = handcuffLocks;
		} else {
			this.handcuffLocks = new HashSet<Handcuffs>();
		}
		
		this.chestLocks = new HashSet<Chest>();
	}
	
	public void addDoorLock(Exit exit) {
		if (exit != null) {
			exitLocks.add(exit);
		}
	}
	
	public void addHandcuffLock(Handcuffs hc) {
		if (hc != null) {
			handcuffLocks.add(hc);
		}
	}
	
	public void addChestLock(Chest c) {
		if (c != null) {
			chestLocks.add(c);
		}
	}
	
	public boolean keyForDoorLock(Exit exit) {
		if (masterKey) {
			return true;
		}
		if (exit == null) {
			return false;
		}
		
		boolean retval = false;
		for (Exit e : exitLocks) {
			if (e.equals(exit)) {
				retval = true;
			}
		}
		return retval;
	}
	
	public boolean keyForHandcuffLock(Handcuffs hc) {
		if (hc == null) {
			return false;
		}
		
		boolean retval = false;
		for (Handcuffs curCuffs : handcuffLocks) {
			if (curCuffs.equals(hc)) {
				retval = true;
			}
		}
		return retval;
	}
	
	public boolean keyForChestLock(Chest c) {
		if (c == null) {
			return false;
		}
		
		boolean retval = false;
		for (Chest curChest : chestLocks) {
			if (curChest.equals(c)) {
				retval = true;
			}
		}
		return retval;
	}
}
